home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 4.4 KB | 169 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWBArray.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodmisc
- #endif
-
- //========================================================================================
- // class FW_CByteArray
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CByteArray)
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::FW_CByteArray
- //----------------------------------------------------------------------------------------
-
- FW_CByteArray::FW_CByteArray() :
- fOwnBuffer(TRUE),
- fOffset(0)
- {
- _buffer = (octet*)NULL;
- _length = 0;
- _maximum = 0;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::FW_CByteArray
- //----------------------------------------------------------------------------------------
-
- FW_CByteArray::FW_CByteArray(void* buffer, unsigned long byteCount) :
- fOwnBuffer(FALSE),
- fOffset(0)
- {
- _buffer = (octet*)buffer;
- _length = byteCount;
- _maximum = byteCount;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::FW_CByteArray
- //----------------------------------------------------------------------------------------
-
- FW_CByteArray::FW_CByteArray(const void* buffer, unsigned long byteCount) :
- fOwnBuffer(FALSE),
- fOffset(0)
- {
- _buffer = (octet*)buffer;
- _length = byteCount;
- _maximum = byteCount;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::FW_CByteArray
- //----------------------------------------------------------------------------------------
-
- FW_CByteArray::FW_CByteArray(unsigned long byteCount) :
- fOwnBuffer(TRUE),
- fOffset(0)
- {
- _buffer = NULL; // so if AllocateBlock fails it is clean
-
- if (byteCount != 0)
- _buffer = (octet*)FW_CMemoryManager::AllocateBlock(byteCount);
-
- _length = byteCount;
- _maximum = byteCount;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::~FW_CByteArray
- //----------------------------------------------------------------------------------------
-
- FW_CByteArray::~FW_CByteArray()
- {
- FW_START_DESTRUCTOR
-
- PrivDisposeByteArray();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::PrivDisposeByteArray
- //----------------------------------------------------------------------------------------
-
- void FW_CByteArray::PrivDisposeByteArray()
- {
- if (fOwnBuffer && _buffer != NULL)
- FW_CMemoryManager::FreeBlock(_buffer);
-
- fOwnBuffer = TRUE;
-
- _buffer = NULL;
- _length = 0;
- _maximum = 0;
- fOffset = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::Set
- //----------------------------------------------------------------------------------------
-
- void FW_CByteArray::Set(void* buffer, unsigned long byteCount)
- {
- PrivDisposeByteArray();
-
- fOwnBuffer = FALSE;
-
- _buffer = (octet*)buffer;
- _length = byteCount;
- _maximum = byteCount;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteArray::SCopyBufferet
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CByteArray::CopyBuffer(void *buffer, unsigned long byteCount)
- {
- FW_ASSERT((fOffset < _length) || (_length == 0));
-
- unsigned long cnt = ((byteCount + fOffset) <= _length) ? byteCount : _length;
-
- FW_CMemoryManager::CopyMemory( _buffer + fOffset,
- buffer,
- cnt);
- fOffset += cnt;
-
- if (fOffset == _length)
- PrivDisposeByteArray();
-
- return cnt;
- }
-
-
-